/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.LoaiSanPham;
import pojo.SanPham;
import util.HibernateUtil;

/**
 *
 * @author DAT
 */
public class LoaiSanPhamDAO {

    public static List<LoaiSanPham> layDanhSachLoaiSanPham() {
        List<LoaiSanPham> ds = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = "select loaiSP from LoaiSanPham loaiSP order by loaiSP.tenLoaiSanPham asc";
        Query query = session.createQuery(hql);
        ds = query.list();
        session.close();
        return ds;
    }
    public static int tinhsoLuongTheoDoiTuong(String maLoaiSanPham,int maDoiTuong){
        Session session=HibernateUtil.getSessionFactory().openSession();
        List<SanPham> ds;
        String hql="from SanPham s where s.loaiSanPham.maLoaiSanPham =:maTH and s.doiTuong.maDoiTuong=:maDT";
        Query query=session.createQuery(hql);
        query.setString("maTH",maLoaiSanPham);
        query.setInteger("maDT", maDoiTuong);
        ds=query.list();
        return ds.size();
    }
}
